/*************************************************************
 * Title: 
 * Description: 
 * Author: Snow Huang
 * Email: Shaobin.Software@gmail.com Shaobin_Software@163.com
 * CreateTime: 2010-8-2 下午09:23:13
 * Copyright © 落羽社区 All right reserved
 ************************************************************/
package snow.core.util.toolkit;

import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * 
 */
public class ServletHelper {

	/**
	 * 清空session中存储的元素
	 * 
	 * @param session
	 */
	public static void clearSession(HttpSession session) {
		if (session != null) {
			Enumeration<?> enumeration = session.getAttributeNames();
			if (enumeration != null) {
				while (enumeration.hasMoreElements()) {
					Object element = enumeration.nextElement();
					if (element instanceof String) {
						session.removeAttribute((String) element);
					}
				}
			}
		}
	}

	public static HttpSession getSessionFrom(HttpServletRequest request) {
		return getSessionFrom(request, false);
	}

	public static HttpSession getSessionFrom(HttpServletRequest request, boolean create) {
		if (request == null) {
			throw new IllegalArgumentException("The Servlet Request must not be null!");
		}
		return request.getSession(create);
	}
}
